CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(kvs)

set(KVS_DIR ${PROJECT_BINARY_DIR}/kvs)
set($ENV{KVS_DIR} ${PROJECT_BINARY_DIR}/kvs)

# 
# OPTIONS
# ref: http://www.cmake.org/Wiki/CMake_Useful_Variables#Compilers_and_Tools
#
option(CMAKE_BUILD_TYPE "CMAKE_BUILD_TYPE" ON)
# option(DEBUG_AND_RELEASE "DEBUG_AND_RELEASE" OFF)
option(DEBUG "DEBUG" OFF)
option(RELEASE "RELEASE" OFF)
option(KVS_TOOL "KVS_TOOL" ON)
option(KVS_SUPPORT_GLUT "KVS_SUPPORT_GLUT" ON)
option(KVS_SUPPORT_QT "KVS_SUPPORT_QT" OFF)
option(KVS_SUPPORT_OPENCV "KVS_SUPPORT_OPENCV" OFF)
option(KVS_SUPPORT_CUDA "KVS_SUPPORT_CUDA" OFF)


#
# CXX_FLAGS 
#
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if(DEBUG)
	# CMAKE
	set(CMAKE_BUILD_TYPE "Debug")
	# KVS
	add_definitions(-ggdb3)
	add_definitions(-DKVS_ENABLE_DEBUG)
	add_definitions(-D_DEBUG)
endif()
if(RELEASE)
	# CMAKE
	set(CMAKE_BUILD_TYPE "Release")
	# KVS
endif()


#
# OPTONAL FLAGS AND SETTINGS
#
# OPENGL
find_package(OpenGL)
find_package(GLEW)
find_package(GLUT)


#
# SET POSTFIX FOR DEBUG BUILD
# ref: http://www.cmake.org/Wiki/CMake_Useful_Variables#Compilers_and_Tools
#
set(CMAKE_DEBUG_POSTFIX "d")


#
# SET INSTALL DIR
#
set(KVS_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
set(KVS_DIR "${KVS_INSTALL_DIR}")


#
# check options
#
MESSAGE("")
MESSAGE("")
MESSAGE("CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
MESSAGE("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
MESSAGE("CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
MESSAGE("")
MESSAGE("PROJECT_NAME=${PROJECT_NAME}")
MESSAGE("test_SOURCE_DIR=${test_SOURCE_DIR}")
MESSAGE("test_BINARY_DIR=${test_BINARY_DIR}")
MESSAGE("PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}")
MESSAGE("PROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}")	
MESSAGE("CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}")
MESSAGE("CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
MESSAGE("CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
MESSAGE("")
# KVS
MESSAGE("")
MESSAGE("DEBUG=${DEBUG}")
MESSAGE("RELEASE=${RELEASE}")
MESSAGE("KVS_SUPPORT_GLUT=${KVS_SUPPORT_GLUT}")
MESSAGE("KVS_SUPPORT_QT=${KVS_SUPPORT_QT}")
MESSAGE("KVS_SUPPORT_OPENCV=${KVS_SUPPORT_OPENCV}")
MESSAGE("KVS_SUPPORT_CUDA=${KVS_SUPPORT_CUDA}")
MESSAGE("KVS_INSTALL_DIR=${KVS_INSTALL_DIR}")
MESSAGE("KVS_DIR=${KVS_DIR}")
MESSAGE("")


# build library
ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Source)
if(KVS_TOOL)
	ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Tool)
endif()
# fix me: write CMakeLists.txt for these subdirs
# ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Example)